//
//  HHWebImage.swift
//  BCWebImageKit
//
//  Created by chun.chen on 2021/8/27.
//  扩展属性

import Foundation

public final class HHWebImage<Base> {
    public let base: Base
    public init(_ base: Base) {
        self.base = base
    }
    
    /// 占位图背景色
    public var placeholderColor :UIColor?
    
    /// 占位图 内容模式,见 枚举
    public var placeholderContentMode :UIView.ContentMode = .scaleAspectFill
}

public protocol HHWebImageCompatible {
    associatedtype CompatibleType
    var hh: CompatibleType { get }
}

public extension HHWebImageCompatible {
    var hh: HHWebImage<Self> {
        return HHWebImage(self)
    }
}

//MARK: - extensions
extension UIImageView: HHWebImageCompatible { }

extension UIButton: HHWebImageCompatible { }

//MARK: - width
/// 根据七牛 url规则 拼接宽度参数 返回对应宽度图片url
/// - Parameters:
///   - url: 图片原始url
///   - width: 宽度
/// - Returns: String
public func ImgWidthURL(_ url: String, width: Int) -> String {
    guard width > 0 else {
        return url
    }
    if url.contains("?") {
        return url + "&imageView2/2/w/" + "\(width)"
    } else {
        return url + "?imageView2/2/w/" + "\(width)"
    }
}
